import React, { Component } from 'react';
import { connect } from 'dva';
import { Button, InputItem, Toast } from 'antd-mobile';
import { Form, Modal } from 'antd';
import Login from '@/components/Login';
import styles from './Login.less';
import {
  removeAuthorization,
  saveAuthorization,
  saveMenus,
  saveOrg,
  saveRoles,
  saveUser,
} from '@/utils/bwdautil';
import { decode } from '@/utils/AesUtil';
import qs from 'qs';

const FormItem = Form.Item;
const { Tab, UserName, Password, Mobile, Captcha, Submit, ImageVerifyCode } = Login;

@connect(({ login, loading }) => ({
  login,
}))
class AhdxLogin extends Component {
  state = {
    type: 'account',
    autoLogin: false,
    verifyCodeUuid: '',
    imageBase64: '',
    isNeedImageCode: false,
    verionData: {},
    pwdInutType: 'text',
  };

  handleSubmit = values => {
    const { dispatch } = this.props;
    dispatch({
      type: 'login/ahdxLogin',
      payload: values,
    }).then(res => {
      if (res.rescode == 200) {
        if (this.props.location.query.code) {
          dispatch({
            type: 'login/ahdxLoginByCode',
            payload: { code: this.props.location.query.code, clientId: res.data.clienId },
            callback: res => {
              if (res.result == 'fail') {
                /*  message.success(res.msg);*/
                Modal.error({ title: '登录失败', content: res.msg });
              }
            },
          });
        } else {
          window.location.href =
            res.data.getAuthorizeCodeUrl +
            qs.stringify(
              {
                client_id: res.data.clienId,
                redirect_uri: window.location.origin + window.location.pathname,
                response_type: res.data.responseType,
              },
              { addQueryPrefix: true }
            );
        }
      }
    });
  };

  async componentDidMount() {
    removeAuthorization();

    this.handleSubmit();
  }

  outfiles;
  render() {
    const { login, submitting } = this.props;
    const { type, imageBase64, isNeedImageCode, verionData, pwdInutType } = this.state;
    return <div className={styles.main}></div>;
  }
}

export default AhdxLogin;
